/**
 * ScoreManager
 * Manage score datas
 **/
var ScoreManager = function() {
	this.currentScore = 0;
	this.bestScore = 0;

	this.init = function() {
		this.load();
	}

	this.updateScore = function(score) {
		this.currentScore += score;
	}

	this.load = function() {
		var data = localStorage.getItem('scores');
		var scores = JSON.parse(data);

		if (scores != null ) {
			if (isNumber(scores['best'])) 
				this.bestScore = scores['best'];
		}
	}

	this.save = function() {
		var scores = [];
		if (this.currentScore > this.bestScore) 
			scores['best'] = this.currentScore;
		else
			scores['best'] = this.bestScore;

		var obj = {};
		for(score in scores) {
			if(typeof scores[score] !== "function") {

				switch(score) {
					default :
						obj[score] = scores[score];
					break;
				}
			}
		}

		var json = JSON.stringify(obj);
		localStorage.setItem('scores', json);
	}

	this.restart = function() {
		this.currentScore = 0;
	}

};